﻿using System.Web;
using BLL;
using Entity;

namespace Web.ashx
{
    /// <inheritdoc />
    /// <summary>
    /// DeleteWaterMeter 的摘要说明
    /// </summary>
    public class DeleteWaterMeter : IHttpHandler
    {
        /// <summary>
        ///     用户信息对象
        /// </summary>
        private readonly YS_YG_YONGHUXX _YS_YG_YONGHUXX = new YS_YG_YONGHUXX();


        /// <summary>
        ///     日志BLL
        /// </summary>
        private readonly SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();
        public void ProcessRequest(HttpContext context)
        {
            var waterMeterNum = context.Request["waterMeterNum"];
            var userId = context.Request["userid"];
            string msg = "";
            var dataResult = BusinessTool.GetShuiBiaoSJZT(waterMeterNum, out msg);
            if (!dataResult)
            {
                //执行销表          
                _YS_YG_YONGHUXX.S_CAOZUOR = LoginInfo.CurrentUser.Account;
                _YS_YG_YONGHUXX.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
                _YS_YG_YONGHUXX.I_YONGHUZT = WordsStruct.I_YONGHUZT.销表;
                //_SYS_LOGBLL.Log(LoginInfo.CurrentUser, "0", "用户管理-销表", OperateState.Delete,
                    //_YS_YG_YONGHUXX, null);
                var helper = new SqlHelper();
                var result = helper.DeleteWaterMeter(waterMeterNum, userId);
                context.Response.Write(result ? "销表操作成功" : "销表操作失败");
            }
            else
            {
                context.Response.Write("该水表近三个月内有数据无法直接销表。");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}